<?php

/** 
* Class used to organize structurally returns and errors of WebService
* 
* @author Edio Hanoway Kepke <edio@aquiris.com>
* @version 1.0 
* @access public
*/ 

class Error 
{    
    /** 
    * Constants used to define the errors web Service
    */
    
    const NOT_EXIST_ERROR = 0;
    
    const INSUFFICIENT_PARAMETERS = 1;
    
    const NOT_EXIST_LOGIN_USER = 2;
    
    const INTERNAL_SERVER_ERROR = 3;
    
    const DUPLICATE_REGISTRY = 4;
    
    const NOT_FOUND_REGISTRY = 5;
    
    const FILE_SIZE_EXCEPTION_PHP = 6;
    
    const FILE_SIZE_EXCEPTION_HTML = 7;
    
    const FILE_PARCIAL_UPLOAD = 8;

    const FILE_NOT_UPLOAD = 9;
    
    const FILE_IS_NOT_ALLOWED = 10;
    
    const FILE_IS_VERY_BIG = 11;
    
    const INVALID_OWNER = 12;
    
    const PARCIAL_DELETE_FILE = 13;
    
    const PARCIAL_DELETE_AUTOR = 14;
    
    const PARCIAL_DELETE_ASSUNTO = 15;
    
    const PARCIAL_DELETE_FILE_REGISTER = 16;        
    
    const NOT_FOUND_FILE = 17;

        /** 
    * Constant is a dictionary, contains errors returned by curl_info ()
    * @access public
    * @name errors
    */     
    public static $webErrors = array(
                                    "100" => "Continue",
                                    "101" => "Switching Protocols",
                                    "200" => "OK (no error)",
                                    "201" => "Created",
                                    "202" => "Accepted",
                                    "203" => "Non-Authoritative Information",
                                    "204" => "No Content",
                                    "205" => "Reset Content",
                                    "206" => "Partial Content",
                                    "300" => "Multiple Choices",
                                    "301" => "Moved Permanently",
                                    "302" => "Moved Temporarily",
                                    "304" => "Not Modified",
                                    "305" => "Use Proxy",
                                    "400" => "Bad Request",
                                    "401" => "Unauthorized",
                                    "402" => "Payment Required",
                                    "403" => "Forbidden",
                                    "404" => "Not Found",
                                    "405" => "Method Not Allowed",
                                    "406" => "Not Acceptable",
                                    "407" => "Proxy Authentication Required",
                                    "408" => "Request Time-Out",
                                    "409" => "Conflict",
                                    "410" => "Gone",
                                    "411" => "Length Required",
                                    "412" => "Precondition Failed",
                                    "413" => "Request Entity Too Large",
                                    "414" => "Request-URL Too Large",
                                    "415" => "Unsupported Media Type",
                                    "500" => "Server Error",
                                    "501" => "Not Implemented",
                                    "502" => "Bad Gateway",
                                    "503" => "Out of Resources",
                                    "504" => "Gateway Time-Out",
                                    "505" => "HTTP Version not supported"
                                );
    
    
    
    /** 
    * variable that has code of error
    * @access public
    * @name $code 
    * @var int
    */ 
    public $code;
    
    
    /** 
    * variable that has information of success post 
    * @access public
    * @name $success 
    * @var boolean
    */ 
    public $success;        
    
    
    /**      
    * @access public
    * @name $description
    * @var String
    */ 
    public $description;        
    
    
    /**
    * Return error object
    * @access public
    * @param $error int Error number
    * @return Error
    */
    public static function getError($error)
    {           
        $tempError = new Error();
        
        $tempError->code = $error;
        
        $tempError->description = self::getErrorDescription($error);
        
        (($error == self::NOT_EXIST_ERROR || $error == 200 ) && !is_null($error))  ? ( $tempError->success = true ):( $tempError->success = false );
                                                 
        return $tempError;
    }
    
    /**
    * Return descrition error
    * @access private
    * @param $error int Error number
    * @return String
    */
    private static function getErrorDescription($error)
    {           
        if(is_null($error))
        {
            return "There is no description";
        }
        
        if($error < 100)
        {
            switch ($error) 
            {
                case 0: return "Requisição processada com sucesso."; break;
                case 1: return "Parametros Insuficientes."; break;
                case 2: return "Usuario não esta logado."; break;
                case 3: return "Internal Server Error."; break;
                case 4: return "There is already a record like this in the database."; break;
                case 5: return "Not Found register in the database"; break;
                case 6: return "O arquivo no upload é maior do que o limite do PHP"; break;
                case 7: return "O arquivo ultrapassa o limite de tamanho especifiado no HTML"; break;
                case 8: return "O upload do arquivo foi feito parcialmente"; break;
                case 9: return "Não foi feito o upload do arquivo"; break;                                            
                case 10: return "Tipo de arquivo não permitido"; break;                                            
                case 11: return "O arquivo não permitodo pelo tamanho!"; break;
                case 12: return "Acesso negado!"; break;
                case 13: return "Arquivo não foi deletado!"; break;
                case 14: return "Autores não foram deletados!"; break;
                case 15: return "Assuntos não foram deletados!"; break;
                case 16: return "Registro não pode ser deletado!"; break;
                case 17: return "Arquivo não encontrado!"; break;
                default: return "There is no description";break;
           }            
        }        
        else 
        {            
            return self::$webErrors[$error];
        }
    }
    
    
    
}

?>
